<?php
include 'secure/core.php';
if(isset($_POST['submit'])){
	$result = $users->updateUser($_POST);
	
	if($result == 1){
		header( 'Location: account.php?msg=2' ) ;
	}
	else{
		header( 'Location: account.php?msg=3' ) ;	
	}		

}
include 'user_header.php';
include 'left.php'; 
$SQL = "SELECT * FROM `users` WHERE `id` = '$_SESSION[userid]'";
$res = $ado->exec($SQL);
$row	=	$ado->fetch($res);
?>
		<div id="right">
		<div class="section">
		<?php if($_GET['msg'] == '1') { ?>
		<div class="message red"><span><b>Error</b>: You must fill "Confirm Password" to update.</span></div>
		<?php } ?>
		<?php if($_GET['msg'] == '2') { ?>
		<div class="message green"><span><b>Success</b>: Account has been successfully updated.</span></div>
		<?php } ?>
		<?php if($_GET['msg'] == '3') { ?>
		<div class="message red"><span><b>Error</b>: Confirm Password was incorrect.</span></div>
		<?php } ?>
				<div class="box">
					<div class="title">
						Manage Account Settings
						<span class="hide"></span>
					</div>
					<div class="content">
						<form action="account.php" method="POST">
							<div class="row">
								<label>Full Name</label>
								<div class="ftp">
								<div class="right"><input type="text" name="fullname" value="<?php echo $row['name'];?>"></div>
								</div>
							</div>
							<div class="row">
								<label>Email</label>
								<div class="ftp">
								<div class="right"><input type="text" name="email" value="<?php echo $row['email'];?>"></div>
								</div>
							</div>
							<div class="row">
								<label>Street Address</label>
								<div class="ftp">
								<div class="right"><input type="text" name="address" value="<?php echo $row['address'];?>"></div>
								</div>
							</div>
							<div class="row">
								<label>Country</label>
								<div class="ftp">
								<div class="right"><?php echo $users->getCountrySelectBox($row['country_iso']);?></div>
								</div>
							</div>
							<div class="row">
								<label>Contact Number</label>
								<div class="ftp">
								<div class="right"><input type="text" name="number" value="<?php echo $row['contact_number'];?>"></div>
								</div>
							</div>
							<div class="row">
								<label>Password</label>
								<div class="ftp">
								<div class="right"><input type="password" name="password" value=""></div>
								</div>
							</div>
							<div class="row">
								<div class="right">
								<button type="submit" class="green" name="submit"><span>Sumbit</span></button>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
<?php include 'footer.php'; ?>